<?php

namespace App\Admin\Controllers;

use App\Admin\Requests\ProfilePasswordUpdateRequest;
use App\Admin\Requests\ProfileUpdateRequest;
use Auth;
use Illuminate\Http\Request;

class ProfileController extends Controller
{
    public function edit(Request $request)
    {
        return view('admin.profile.edit', auth('admin')->user()->toArray());
    }

    public function update(ProfileUpdateRequest $request)
    {
        $adminUser           = auth('admin')->user();
        $adminUser->staff_id = $request->input('staff_id');
        $adminUser->name     = $request->input('name');
        $adminUser->nickname = $request->input('nickname');
        $adminUser->call_id  = $request->input('call_id', '0');
        $adminUser->email    = $request->input('email', '0');
        $adminUser->avatar   = $request->input('avatar', '0');
        $adminUser->save();
        return $this->success('修改成功');
    }

    public function editPassword()
    {
        return view('admin.profile.edit_password');
    }

    public function updatePassword(ProfilePasswordUpdateRequest $request)
    {
        $adminUser           = Auth::guard('admin')->user();
        $adminUser->password = bcrypt($request->input('password'));
        $adminUser->save();
        return $this->success('修改成功');
    }
}
